<?php
namespace Admin\Logic;
use \Think\Model;
class FungroLogic extends Model{
	
	Protected $autoCheckFields 	= false;
	Protected $tableName 		= 'functiongroup'; 
	
	//获取第1级功能分组
	public function listlev1(){
		return	$this->getList(0);
	}

	/*
	 * 获取子功能分组
	 * parent_id	过滤条件，值为上一级id
	 */	
	public function getList($parent_id){
		
		$condition['parent_id']	= $parent_id;
		$FGlist					= M($this->tableName)->where($condition)->select();
		return	$FGlist;
	}	

	//获取所有分组
	public function getAllList(){
		
		$FGlist					= $this->listlev1();
		foreach($FGlist as $v => $k){
			$FGlist[$v]['subFG']	= $this->getList($k['id']);
		}
		return	$FGlist;
	}
	

	/*
	 * 获取父功能分组
	 * child_id	过滤条件，值为上一级id
	 */	
	public function getParentid($child_id){
		
		$parent_id		= M($this->tableName)->getFieldById($child_id,'parent_id');
		return	$parent_id;
	}		
	
	//按操作数组获取对应分组数据
	public function getGroupByArray($array){
		
		$OA			= D('Operauth','Logic');
		foreach($array as $v => $k){
			if($k>0){
				$FGarray[]	= $OA->getFGid($k);
			}
		}
		$FGarray	= array_flip(array_flip($FGarray));
		foreach($FGarray as $v => $k){
			$list[$this->getParentid($k)][]	= $k;
		}
		return $list;
	}
	
}